package com.jcl.recruit.resume.provider;

import com.jcl.recruit.mapper.provider.SqlProvider;
import com.jcl.recruit.resume.model.ResumePersInfo;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

public class ResumePersInfoSqlProvider implements SqlProvider<ResumePersInfo> {

    private static final String TABLE_NAME = "resume_pers_info";

    public String insert(ResumePersInfo entity) {
        BEGIN();
        INSERT_INTO(TABLE_NAME);
        
        if (entity.getResumeId() != null) {
            VALUES("resume_id", "#{resumeId,jdbcType=INTEGER}");
        }
        if (entity.getCorpCode() != null) {
            VALUES("corp_code", "#{corpCode,jdbcType=VARCHAR}");
        }

        if (entity.getName() != null) {
            VALUES("name", "#{name,jdbcType=VARCHAR}");
        }

        if (entity.getSex() != null) {
            VALUES("sex", "#{sex,jdbcType=VARCHAR}");
        }

        if (entity.getMobile() != null) {
            VALUES("mobile", "#{mobile,jdbcType=VARCHAR}");
        }

        if (entity.getEmail() != null) {
            VALUES("email", "#{email,jdbcType=VARCHAR}");
        }

        if (entity.getBirthday() != null) {
            VALUES("birthday", "#{birthday,jdbcType=DATE}");
        }

        if (entity.getCurrentCity() != null) {
            VALUES("current_city", "#{currentCity,jdbcType=VARCHAR}");
        }

        if (entity.getCurrentAddress() != null) {
            VALUES("current_address", "#{currentAddress,jdbcType=VARCHAR}");
        }

        if (entity.getCurrentSalary() != null) {
            VALUES("current_salary", "#{currentSalary,jdbcType=VARCHAR}");
        }

        if (entity.getSalaryStart() != null) {
            VALUES("salary_start", "#{salaryStart,jdbcType=VARCHAR}");
        }

        if (entity.getSalaryEnd() != null) {
            VALUES("salary_end", "#{salaryEnd,jdbcType=VARCHAR}");
        }

        if (entity.getWorkYear() != null) {
            VALUES("work_year", "#{workYear,jdbcType=INTEGER}");
        }

        if (entity.getWorkLastPosition() != null) {
            VALUES("work_last_position", "#{workLastPosition,jdbcType=VARCHAR}");
        }

        if (entity.getWorkLastCompany() != null) {
            VALUES("work_last_company", "#{workLastCompany,jdbcType=VARCHAR}");
        }

        if (entity.getEduLastEducation() != null) {
            VALUES("edu_last_education", "#{eduLastEducation,jdbcType=VARCHAR}");
        }

        if (entity.getEduLastSchool() != null) {
            VALUES("edu_last_school", "#{eduLastSchool,jdbcType=VARCHAR}");
        }

        if (entity.getEduLastSchoolTag() != null) {
            VALUES("edu_last_school_tag", "#{eduLastSchoolTag,jdbcType=VARCHAR}");
        }

        if (entity.getEduLastMajor() != null) {
            VALUES("edu_last_major", "#{eduLastMajor,jdbcType=VARCHAR}");
        }
        return SQL();
    }

    public String updateByPrimaryKey(ResumePersInfo entity) {
        BEGIN();
        UPDATE(TABLE_NAME);

        if (entity.getResumeId() != null) {
            SET("resume_id=#{resumeId,jdbcType=INTEGER}");
        }

        if (entity.getName() != null) {
            SET("name=#{name,jdbcType=VARCHAR}");
        }

        if (entity.getSex() != null) {
            SET("sex=#{sex,jdbcType=VARCHAR}");
        }

        if (entity.getMobile() != null) {
            SET("mobile=#{mobile,jdbcType=VARCHAR}");
        }

        if (entity.getEmail() != null) {
            SET("email=#{email,jdbcType=VARCHAR}");
        }

        if (entity.getBirthday() != null) {
            SET("birthday=#{birthday,jdbcType=DATE}");
        }

        if (entity.getCurrentCity() != null) {
            SET("current_city=#{currentCity,jdbcType=VARCHAR}");
        }

        if (entity.getCurrentAddress() != null) {
            SET("current_address=#{currentAddress,jdbcType=VARCHAR}");
        }

        if (entity.getCurrentSalary() != null) {
            SET("current_salary=#{currentSalary,jdbcType=VARCHAR}");
        }

        if (entity.getSalaryStart() != null) {
            SET("salary_start=#{salaryStart,jdbcType=VARCHAR}");
        }

        if (entity.getSalaryEnd() != null) {
            SET("salary_end=#{salaryEnd,jdbcType=VARCHAR}");
        }

        if (entity.getWorkYear() != null) {
            SET("work_year=#{workYear,jdbcType=INTEGER}");
        }

        if (entity.getWorkLastPosition() != null) {
            SET("work_last_position=#{workLastPosition,jdbcType=VARCHAR}");
        }

        if (entity.getWorkLastCompany() != null) {
            SET("work_last_company=#{workLastCompany,jdbcType=VARCHAR}");
        }

        if (entity.getEduLastEducation() != null) {
            SET("edu_last_education=#{eduLastEducation,jdbcType=VARCHAR}");
        }

        if (entity.getEduLastSchool() != null) {
            SET("edu_last_school=#{eduLastSchool,jdbcType=VARCHAR}");
        }

        if (entity.getEduLastSchoolTag() != null) {
            SET("edu_last_school_tag=#{eduLastSchoolTag,jdbcType=VARCHAR}");
        }

        if (entity.getEduLastMajor() != null) {
            SET("edu_last_major=#{eduLastMajor,jdbcType=VARCHAR}");
        }
        
        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}